{include file='Public/header' /}
<div class="layui-layout layui-layout-admin">
{include file='Public/head' /}	
{include file='Public/side' /}	
	<div class="layui-body"> 
{include file='Public/crumbs' /}
		<!-- 内容主体区域 -->
		<div class="shu-body shu-setting">
			<div class="layui-fluid">
				<div class="shu-tipe">
				
				<blockquote class="layui-elem-quote">
					<div id="update">
						<p>程序版本：程序版本：{$Think.CONFIG.Version}， Thinkphp版本：{$Think.Version}， Layui版本：{$Think.CONFIG.Layui_Version}</p>
						<p id="upmsg"><i class="ace-icon fa fa-refresh fa-spin blue"></i></p>
					</div>
					<div id="uploading"></div>
				</blockquote>
		
				</div>
			</div>
		</div>
		<!-- 内容主体区域 END-->
	</div>
{include file='Public/footer' /}
<script>
$(function () {
	$.ajax({
		type: 'GET',
		url: '{$Think.CONFIG.UPDATE_URL}?v={$Think.CONFIG.Version}',
		dataType: 'jsonp', //跨域最好是用jsonp，如不用就要在url里手动一个 callback=? 这样手动GET出去
		jsonp:'callback',
		success: function (json) {
			if (json.result == 'no') {
				$("#upmsg").removeClass().html("目前还没有适合您当前版本的更新！");
			} else if (json.result == 'yes') {
				
				$("#upmsg").removeClass().html("检查到新版本 " + json.ver + "，<a class=\"up_btn\"  href=\"javascript:;\" nickname=\"" + json.ver + "\" val=\"" + json.file + "\">立即升级</a>");
			
			}
		},
		error: function () {
			$("#upmsg").removeClass().html("悲剧了，网络故障，请稍后再试！");
		}

	});
})
</script>	
<script>
layui.use(['jquery','layer','form'], function(){
	var jq = layui.jquery,layer=layui.layer,form = layui.form;
	  jq('.up_btn').click(function(){
		var name = jq(this).attr('nickname');
		var file = jq(this).attr('val');
		layer.confirm('确定升级到【'+name+'】? 由于网络环境差异，为避免在线升级失败造成不可挽回的损失，升级前请做好数据备份工作。同时我们不建议对源码修改过的用户进行在线升级！', function(index){
		  loading = layer.load(2, {
			shade: [0.2,'#000']
		  });
		  jq('#uploading').html('<i class="ace-icon fa fa-spinner fa-spin orange bigger-120"></i>系统升级中...请勿关闭窗口');
		  jq('#upmsg').html(''); 
		  jq.getJSON("{:url('updating')}?file=" + file,function(data){
			if(data.code == 1){
			  layer.close(loading);
			  layer.msg(data.msg, {icon: 1, time: 1000}, function(){
				location.reload();
			  });
			}else{
			  layer.close(loading);
			  layer.msg(data.msg, {icon: 2, anim: 6, time: 3000},function(){
				location.reload();  
			  });
			}
		  });
		});   
	  });

	
	
	
		
	
	
});
</script>